package com.kumarn.android.drovoice;

import com.kumarn.android.drovoice.R;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.IBinder;
import android.os.Vibrator;
import android.util.Log;
import android.widget.Toast;

public class VolVoiceService extends Service {

	//BatteryHandler
	public static Handler _BatteryHandler;
	public static Handler _BatteryHandler_reg;
	public static Handler _BatteryHandler_unreg;
	public  final static BatteryBroadcastReceiver _BatteryBroadcastReceiver = new BatteryBroadcastReceiver();

	//ScreenHandler
	public static Handler _ScreenHandler;
	public static Handler _ScreenHandler_unreg;
	public  final static ScreenBroadcastReceiver _ScreenBroadcastReceiver = new ScreenBroadcastReceiver();

	public Vibrator vibrator;
	private long pattern[] = {0, 200,100, 200};
	public MediaPlayer mediaPlayer;


	@Override
	public void onStart(Intent in, int si) {

	}

	@Override
	public void onCreate() {

		_BatteryHandler_reg = new Handler() {
			@Override
			public void handleMessage(android.os.Message msg) {

				/* レシーバ登録（バッテリー */
		    	IntentFilter batteryFilter = new IntentFilter();
		    	batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
				registerReceiver(_BatteryBroadcastReceiver, batteryFilter);
				_BatteryBroadcastReceiver.setDebugUnregister(true);

			}
		};

		_BatteryHandler_unreg = new Handler() {
			@Override
			public void handleMessage(android.os.Message msg) {


				/* レシーバ解除（バッテリー */
	        	unregisterReceiver(_BatteryBroadcastReceiver);
	        	_BatteryBroadcastReceiver.setDebugUnregister(false);
			}
		};

		_ScreenHandler = new Handler() {
			@Override
			public void handleMessage(android.os.Message msg) {

				//音声再生
				mediaPlayer = MediaPlayer.create(VolVoiceService.this,R.raw.screen_off);
				mediaPlayer.start();

			}
		};

		_ScreenHandler_unreg = new Handler() {
			@Override
			public void handleMessage(android.os.Message msg) {

				/* レシーバ解除（バッテリー */
	        	unregisterReceiver(_ScreenBroadcastReceiver);
	        	_ScreenBroadcastReceiver.setDebugUnregister(false);
			}
		};

	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

}